// pages/payDone/payDone.js
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
const App = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        goodsList:[],
        memberLeaderObj: {},
        imageIconList: {
            time: "/static/images/paydone/time.png",
            success: "/static/images/paydone/success.png",
            phone: "/static/images/paydone/phone.png",
        },
        goodsList: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getRecommendGoodList();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        const memberLeaderObj = App.globalData.memberLeaderObj;
        this.setData({
            memberLeaderObj
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title: '108元福利放送中，仅限今天！', //转发页面的标题
            imageUrl: '/static/images/share.jpeg',
            path:"/pages/index/index"
        }
    },
    goToOrder(){
        wx.navigateTo({
            url: "/pages/order/order",
        })
    },
    
    getRecommendGoodList(){
        this.findGoodsRequest({
          isRecommend: true
        }).then(res=>{
          console.log(1223,res.result)
          if(res.result.length > 0){
            this.setData({
              goodsList:res.result,
            })
            console.log(222,this.data.goodsList)
          }
        }).catch(err=>{
          console.log(err.message)
        })
      },
      findGoodsRequest(data = {}){
        wx.showLoading({
          title: "正在加载"
        })
    
        let url = api.indexUrl.getGoodList+'?current=1&size=21';
    
        return new Promise((resolve, rejected)=>{
          util.request(url, data, "POST").then((res)=>{
            resolve(res);
            wx.hideLoading();
          }).catch(err=>{
            rejected(err);
            wx.hideLoading();
          })
        })
      },
});

